#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e4 + 5;
const int K = 1e7 + 5;

int n, m;
int ask[N], ans[N];
int head[N];
int ver[N << 1], W[N << 1], Next[N << 1], tot;
void add(int u, int v, int w) {
  ++tot;
  ver[tot] = v;
  W[tot] = w;
  Next[tot] = head[u];
  head[u] = tot;
}
int del[N];
int sz[N], mx[N];
int rt;
void get_rt(int u, int fu, int cnt) {
  sz[u] = 1, mx[u] = 0;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (del[v] || v == fu) continue;
    get_rt(v, u, cnt);
    sz[u] += sz[v];
    mx[u] = max(mx[u], sz[v]);
  }
  mx[u] = max(mx[u], cnt - sz[u]);
  if (!rt || mx[rt] > mx[u]) rt = u;
}
void get_dis(int u, int fu, int d, vector<int>& res) {
  res.push_back(d);
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (del[v] || v == fu) continue;
    get_dis(v, u, d + W[i], res);
  }
}
bool judge[K];
void calc(int u) {
  judge[0] = 1;
  vector<int> dis;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (del[v]) continue;
    vector<int> now;
    get_dis(v, u, W[i], now);
    rep(j, 1, m) {
      if (ans[j]) continue;
      for (int x : now) {
        if (ask[j] >= x && judge[ask[j] - x]) {
          ans[j] = 1;
          break;
        }
      }
    }
    for (int x : now) {
      if (x <= 1e7) dis.push_back(x), judge[x] = 1;
    }
  }
  for (int x : dis) judge[x] = 0;
}
void divide(int u, int cnt) {
  rt = 0;
  get_rt(u, 0, cnt);
  u = rt;
  // handle path through rt
  calc(u);
  del[u] = 1;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (del[v]) continue;
    divide(v, sz[v] > sz[u] ? sz[v] - sz[u] : sz[v]);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 2, n) {
    int u, v, w;
    cin >> u >> v >> w;
    add(u, v, w), add(v, u, w);
  }
  rep(i, 1, m) cin >> ask[i];
  divide(1, n);
  rep(i, 1, m) {
    if (ans[i])
      cout << "AYE" << endl;
    else
      cout << "NAY" << endl;
  }
  return 0;
}